﻿using System.Text;
using System.Threading.Tasks;
using Model.Admin;
using Xproject.Framework.Utility.Extensions;
using Xproject.Framework.Core.Repositories;
using Xproject.Framework.Utility.ExceptionHandling;
using Xproject.Framework.Core;
using System.Linq.Expressions;
using Model.Admin.DTO;
using System;
using System.Linq;
using System.Collections.Generic;

namespace Repository.WXProjectAdmin
{
   public static  class AdminRoleRep
    {

        public static AdminRole GetByRoleId(this IRepositoryAsync<AdminRole> repository, int roleId)
        {
            Expression<Func<AdminRole, bool>> express = i => 1 == 1;

            express = express.AndAlso(i => i.RoleId == roleId);

            return repository.Query().Where(express).Select().OrderByDescending(i => i.CreateTime).FirstOrDefault();
        }

        public static List<AdminRole> GetAllRoleList(this IRepositoryAsync<AdminRole> repository, string site, string roleName, string roleDesc)
        {
            Expression<Func<AdminRole, bool>> express = i => 1 == 1;
            express = express.AndAlso(i => i.Enable == 1 );
            if (!string.IsNullOrEmpty(roleName))
            {
                express = express.AndAlso(i => i.RoleName.Contains(roleName));
            }
            if (!string.IsNullOrEmpty(roleDesc))
            {
                express = express.AndAlso(i => i.RoleDesc.Contains(roleDesc));
            }
            return repository.Query().Where(express).Select().ToList();
        }
    }
}
